package com.bt.framework.base

import android.os.Bundle
import android.view.View
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import java.lang.reflect.ParameterizedType
/**
 *@author:hxm
 *@date: 2025/7/7 22:04
 *@version:
 *@description: DataBinding+ViewModel基类
 */
abstract class BaseMvvmFragment<DB : ViewDataBinding, VM : ViewModel> :
    BaseDataBindingFragment<DB>() {

    lateinit var mViewModel: VM

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        initViewModel()
        super.onViewCreated(view, savedInstanceState)
    }

    open fun initViewModel() {
        val argument = (this.javaClass.genericSuperclass as ParameterizedType).actualTypeArguments
        mViewModel = ViewModelProvider(this)[argument[1] as Class<VM>]
    }

}